<%--
  Created by IntelliJ IDEA.
  User: zhuya
  Date: 2016/1/28
  Time: 16:45
  办事咨询 ----我的提问页面
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@ page language="java" import="com.oceansoft.mobile.econsole.modules.sys.entity.SysUser" %>
<%@ page language="java" import="com.oceansoft.mobile.econsole.common.constant.Constant" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="privilege" uri="/WEB-INF/privilege.tld" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title>我要咨询</title>
    <link rel="stylesheet" href="<c:url value="/resource/wechat/css/frozen.css"></c:url>">
    <link rel="stylesheet" type="text/css" href="<c:url value="/resource/wechat/css/main.css"></c:url>"/>
    <link type="text/css" href="<c:url value='/resource/wx/newcss/common.css'/>" rel="stylesheet"/>
    <script type="text/javascript" src="<c:url value='/resource/wx/newjs/common.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/resource/wx/js/util.js'/>"></script>
</head>
<body class="bg_fff" ontouchstart>
<section class="ui-container">
    <div class="ui-form">
        <form id="askForm" method="post">
            <input type="hidden" name="pt" value="${pt}"/>
            <div class="ui-form-item ui-border-b">
                <label>
                    <span class="text_red">*</span>咨询标题：
                </label>
                <input id="title" type="text" placeholder="您可以输入50个字" name="subject" maxlength="50">
            </div>
            <div class="ui-form-item ui-form-item-textarea ui-border-b">
                <label>
                    <span class="text_red">*</span>咨询内容：
                </label>
                <textarea id="content" placeholder="您可以输入200/200个字" name="content" maxlength="200"></textarea>
            </div>
<%--            <div class="ui-form-item ui-border-b">
                <label><span class="text_red">*</span>是否公开</label>
                <label class="ui-radio" style="margin-left: 95px;margin-top: 10px;">
                    <input type="radio" name="ispublic" checked="checked" value="0">公开
                    <input type="radio" name="ispublic" style="margin-left: 10px;" value="1">不公开
                </label>
            </div>--%>
            <div class="ui-form-item ui-border-b" style="position: relative;">
                <label><span class="text_red">*</span>图片验证：</label>
                <input type="text" placeholder="" maxlength="4" id="verCode" name="validateCode" required value="">
                <img id="codeImg" src="" onclick="getImg()"
                     style="position: absolute; top: 4px; right: 10px; width: 75px; height: 36px;">

            </div>

            <div class="ui-form-item ui-border-b">
            <label><span class="text_red">*</span>咨询部门：</label>
            <div class="ui-select">
            <select id="parentDept" onchange="doChoiceChildDept(this)">
            </select>
            </div>
            </div>
            <div id="child" class="ui-form-item ui-border-b" style="display:none">
                <label></label>
                <div class="ui-select">
                    <select id="childDept" onchange="doChoiceDept(this);">
                    </select>
                </div>
            </div>
            <input type="hidden" name="validateId" id="validateId" value="1">
            <input type="hidden" name="consultant" value="${member.guid}"> <%-- 咨询人guid--%>
            <input type="hidden" name="deptId" id="advisoryOrgId" value="370600000000"> <%-- //要咨询部门ID--%>
            <input type="hidden" name="deptName" id="advisoryOrgName" value="山东省烟台市公安局"> <%-- //要咨询部门名称--%>

            <%--<input type="hidden" name="advisoryCaseGuid" id="advisoryCaseGuid" value=" "> &lt;%&ndash; //咨询事项guid&ndash;%&gt;--%>
            <input type="hidden" name="consultantName" id="userName" value="${member.aliasName}"> <%-- //咨询人姓名--%>
            <input type="hidden" name="telephone" id="advisoryMobile" value="${member.userName}"> <%-- //咨询人电话--%>
            <input type="hidden" name="isAnonymous" id="isAnonymous" value="1">
            <input type="hidden" name="ispublic" id="ispublic" value="0"><%-- //是否公开，所以咨询全部公开--%>
        </form>

    </div>
    <div class="ui-btn-wrap">
        <button id="btn_query" class="ui-btn-lg ui-btn-primary" onclick="doSubmit();">
            提交
        </button>
    </div>
</section>

<script src="<c:url value='/resource/js/jquery-2.0.min.js'/>"></script>
<script src="<c:url value="/resource/js/jquery.serializejson.min.js"></c:url>"></script>
<script type="text/javascript" src="<c:url value='/resource/wx/js/common.js'/>"></script>
<script>

    var genGuid;
    $(function () {
        getImg();
    });
    function getImg() {
        genGuid = newGuid().ToString("D");
        $("#validateId").val(genGuid);
        $.ajax({
            url: '<c:url value="/api/code/get/'+ genGuid +'" />',
            type: 'get',
            dataType: 'json',
            success: function (resp) {
                if (resp && resp.succ) {
                    $("#codeImg").attr("src", "data:image/png;base64," + resp.data)
                } else {
                    alert(resp.msg);
                }
            }
        });
    }

   $(function () {
        $.ajax({
            url: "<c:url value="/api/Org/orglist/370600000000"></c:url>",
            success: function (resp) {
                var option = "<option value='370600000000'>市局</option>";
                if (resp.data) {
                    var data = resp.data;
                    for (var i = 0; i < data.length; i++) {
                        option += "<option value='" + data[i].guid + "'>" + data[i].deptName + "</option>";
                    }
                    $("#parentDept").append(option);
                }
            },
            error: function (resp) {
            }
        });
    });

    function doChoiceChildDept(obj) {
        var advisoryOrgId = $(obj).val();
        if (advisoryOrgId == '370600000000') {
            $("#advisoryOrgId").val(advisoryOrgId);
            $("#advisoryOrgName").val('请选择');
            $("#childDept").empty();
            $("#child").hide();
        } else {
            $("#child").show();
            var advisoryOrgName = $("#parentDept").find("option:selected").text();
            //var advisoryOrgName = $(obj).text();
            $("#advisoryOrgId").val(advisoryOrgId);
            $("#advisoryOrgName").val(advisoryOrgName);
            $("#childDept").empty();

            $.ajax({
                url: '<c:url value="/api/Org/orglist/'+advisoryOrgId+'"></c:url>',
                success: function (resp) {
                    var option = "";
                    if (resp.data) {
                        var data = resp.data;
                        option += "<option value=''>请选择</option>";
                        for (var i = 0; i < data.length; i++) {
                            option += "<option value='" + data[i].guid + "'>" + data[i].deptName + "</option>";
                        }
                        $("#childDept").append(option);
                    } else {
                        $("#childDept").append("<option value=''>请选择</option>");
                    }
                },
                error: function (resp) {
                }
            });
        }
    }

    function doChoiceDept(obj) {
        var advisoryOrgId = $(obj).val();
        var advisoryOrgName = $("#childDept").find("option:selected").text();
        if (advisoryOrgId == '' || advisoryOrgId == null) {
            advisoryOrgId = $("#parentDept").find("option:selected").val();
            advisoryOrgName = $("#parentDept").find("option:selected").text();
        }
        $("#advisoryOrgId").val(advisoryOrgId);
        $("#advisoryOrgName").val(advisoryOrgName);
    }

    function checkButtonState() {
        if ($("#inputName").val())
            $("#searchButton").attr("am-mode", "blue");
        else
            $("#searchButton").attr("am-mode", "blue disabled");
    }
    function doSubmit() {
        if ($("#title").val() == "") {
            toast("请输入咨询标题", 1500);
            return;
        }
        if ($("#content").val() == "") {
            toast("请输入咨询内容", 1500);
            return;
        }
        var verCode = $("#verCode").val();
        if (!verCode) {
            alert("图片验证码不能为空");
            return;
        }

        var form = $("#askForm").serializeJSON();
        $("#btn_query").attr("disabled", "disabled");
        $.ajax({
            url: "<c:url value="/api/matters/ask/question"></c:url>",
            data: JSON.stringify(form),
            type: 'post',
            contentType: "application/json",
            success: function (resp) {
                if (resp.succ) {
                    toast("问题已经提交");
                    setTimeout(function () {
                        location.href = "<c:url value='/weixin/wx_member/bszx/myindex?pt=${pt}'/>";
                    }, 1000);
                } else {
                    toast("提交失败");
                    $("#btn_query").attr("disabled", false);
                    getImg();
                }
            },
            error: function (resp) {
                toast("提交失败,请重新操作");
            }
        });

    }
</script>
</body>
</html>
